package com.algorithm.stack;/*
 *@Author:DOWN
 *@Date:2021/12/14 18:10
 *@Comment:
 */

import java.util.Stack;

public class StackTest {

    public static void main(String[] args){
        ArrayStack<Integer> arrayStack=new ArrayStack<>();
        for(int i=0;i<5;i++){
            arrayStack.push(i);
            System.out.println(arrayStack.toString());
        }
        arrayStack.pop();
        System.out.println(arrayStack.toString());
    }
    public boolean isValid(String s){
        Stack<Character> stack=new Stack<>();
        for(int i=0;i<s.length();i++){
            char c = s.charAt(i);
            if(c=='('||c=='['||c=='{'){
                stack.push(c);
            }else {
                if(stack.isEmpty()){
                    return false;
                }
                char oc=stack.pop();
                if(oc=='('&&c!=')'){
                    return false;
                }
                if(oc=='['&&c!=']'){
                    return false;
                }
                if(oc=='{'&&c!='}'){
                    return false;
                }
            }
        }
        return stack.isEmpty();
    }
}
